
import { ref, watch, reactive, getCurrentInstance } from "vue"
import {Plus, Search} from '@element-plus/icons-vue'
import request from '@/utils/request'
import $button from '@/button'
export function saleListApi(dataRequest) {
    return request({
        url: "/sale/list",
        method: "POST",
        data: dataRequest
    });
}
export function orderDetailApi(dataRequest) {
    return request({
        url: "/order/item/list",
        method: "POST",
        data: dataRequest
    });
}
export function orderInfoApi(dataRequest) {
    return request({
        url: "/order/" + dataRequest,
        method: "GET",
    });
}
// 申请退款
export function refundApplyApi(dataRequest) {
    return request({
        url: "/order/refund/apply",
        method: "POST",
        data: dataRequest
    });
}
export const tableItem = reactive({
    select: true,//多选框
    loading: false,
    index: !true,//顺序
    expandAll: false,//树形默认展开
    tree: true,//树形
    align: 'center',
    column: [
        {
            label: '姓名',
            prop: 'name',
        },
        {
            label: '身份证号',
            prop: 'idCard',
        },
        {
            label: '手机号',
            prop: 'phone',
        },
        {
            label: '科目',
            prop: 'courseName',
        },
        {
            label: '账号期限',
            htmlContent: row => { return `<span>${row.dayAmount || 0 }天</span> `}
        },
        {
            label: '学员单价',
            htmlContent: row => { return `<span>${row.price || 0 }元</span> `}
        },
        {
            label: '是否退款',
            prop: 'refundStatusCode',
            htmlContent: row => {
                let result = ''
                switch (row.refundStatusCode) {
                    case 'refunding': result = '退款中'; break;
                    case 'success': result = '退款成功'; break;
                    case 'failed': result = '退款失败'; break;
                    case 'cancel': result = '已取消'; break;
                    case 'non': result = ''; break;
                }
                return `<span>${result ||
                    ''}</span> `
            },
        },
    ],
    pageInfo: {
        request: {
            "orderId": '',
            "name": "",
            "idCard": "",
            "refundStatusCode": ""
        },
        pagesClose: true,
        closeMountedPaging: true,//是否关闭分页显示
        url: '',//分页路由，不传的话需要传入自定义的分页函数paging 传入时定义的分页函数paging会失效
        method: 'GET',//分页请求方法，不传默认为POST
        // 分页函数paging
        paging: function () {
            tableItem.loading = true
            tableItem.tableData.data=[]
            tableItem.tableData.total=0
            orderDetailApi(tableItem.pageInfo.request).then(res => {
                tableItem.tableData.data = res.rows
                tableItem.loading = false
            }).catch(() => { tableItem.loading = false });
        }
    },
    tableData: {
        total: '',//分页总计
        // 分页数据
        data: []
    },
    // 操作栏按钮
    btnArray: [],
    selectChange: function (row) {
    },
})
export const operationItem = reactive({
    defaultSearch: false,//默认搜索按钮
    SearchText: '',
    defaultRefresh: false,//默认重置按钮
    customTableHeader: false,//
    SearchItem: [
        {
            code: "name",
            name: "姓名",
            type: "input",
        },
        {
            code: "idCard",
            name: "身份证号",
            type: "input",
        },
        {
            code: "refundStatusCode",
            name: "是否退款",
            type: "select",
            options: [
                {
                    value: 'refunding',
                    label: '退款中'
                },
                {
                    value: 'success',
                    label: '退款成功'
                },
                {
                    value: 'failed',
                    label: '退款失败'
                },
                {
                    value: 'cancel',
                    label: '已取消'
                },
            ]
        },

    ],
    menuArray: [
        {
            show: true,
            type: 'primary',
            text: '查询',
            icon: Search,
            handle: () => {
            }
        },
        {
            show: true,
            type: 'primary',
            text: '退款',
            hasPermi: [$button.courseorderRefundadd || null],
            icon: Plus,
            customParameters: 'add',//自定义函数参数
            handle: () => {
                console.log('handle')
            }
        },
    ]
})
